package ch.six4rty.doodle.data
{
	/**
	 * Poll Data Object
	 * @author Tiago Dias [six4rty.ch, Switzerland]
	 */
	
	import nl.demonsters.debugger.MonsterDebugger;

	public class PollData
	{
		
		public var _initiator				:InitiatorData;
		
		public var _lastUpdate				:String;
		public var _title					:String;
		public var _state					:String;
		public var _writeOnce				:String;
		public var _hidden					:String;
		public var _byInvitation			:String;
		public var _requiredAddress			:String;
		public var _requiredEmail			:String;
		public var _requiredPhone			:String;
		
		public var _participants			:Array				= new Array();
		public var _comments				:Array				= new Array();
		
		public var _optionsLen				:int;
		
		private var _xml					:XML;
		
		namespace doodleNS 					= "http://doodle.com/xsd1";
		
		/**
		 * 
		 * @param xml
		 * 
		 */		
		public function PollData( xml:XML )
		{
			_xml							= xml;
			
			MonsterDebugger.trace(this, _xml, 0xff0000 );
			
			use namespace doodleNS;
			
			_initiator						= new InitiatorData( XML( _xml.initiator ) );
			_lastUpdate						= _xml.latestChange;
			_title							= _xml.title;
			_state							= _xml.state;
			_writeOnce						= _xml.writeOnce;
			_hidden							= _xml.hidden;
			_byInvitation					= _xml.byInvitationOnly;
			_requiredAddress				= _xml.requireAddress;
			_requiredEmail					= _xml.requireEMail;
			_requiredPhone					= _xml.requirePhone;
			
			_optionsLen						= _xml.options.length();
			
			for each ( var participant:XML in _xml.participants.participant )
			{
				var userData:UserData		= new UserData( participant );
				_participants.push( userData );
			}
			
			for each ( var comment:XML in _xml.comments.comment )
			{
				var commentData:CommentData = new CommentData( comment );
				_comments.push( commentData );
			}
		}
	}
}